import {defineStore} from "pinia";
import {ref} from "vue";
import {getCurrentUser} from "@/api/user";

export const useLoginStore = defineStore('counter', () => {
    const loginUser = ref<any>({
        userId: null,
        userName: '未登录',
        avatar: null,
        phone: null
    })

    // 远程获取登录信息
    async function fetchLoginUser(){
        const res = await getCurrentUser();
        if(res.data.code === 200 && res.data.data){
            loginUser.value = res.data.data;
        }
    }

    function setLoginUser(newLoginUser:any){
        loginUser.value = newLoginUser;
    }

    return { loginUser,fetchLoginUser,setLoginUser }
})
